package com.example.tms.mapper;

import com.example.tms.bean.DeptInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 部门信息
 */
@Repository
public interface DeptMapper extends JpaRepository<DeptInfo, String> {

    //查询部门信息列表（父节点id）
    @Query(value = "select * from dept_info where fjdid = ?1 and sfcz = true",nativeQuery = true)
    List<DeptInfo> findByFjdid(String fjdid);

    //查询部门信息（部门id）
    @Query(value = "select * from dept_info where sfcz = true ", nativeQuery = true)
    List<DeptInfo> findAll();

    //查询部门信息（部门id）
    @Query(value = "select * from dept_info where bumenid = ?1 and sfcz = true ", nativeQuery = true)
    DeptInfo findByBumenid(String bumenid);

    //查询部门信息（部门名称）
    DeptInfo findByName(String name);

    //删除部门信息（假删除 部门id）
    @Query(value = "update dept_info set sfcz = false where bumenid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void deleteByBumenid(String bumenid);

}

